home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 14
/
Aminet 14 - Oct 1996.iso
/
TCalc
/
English
/
TurboCalc3.5Demo
/
Programmer
/
Examples.lha
/
object_logo.tclib.s
< prev
next >
Wrap
Text File
|
1994-11-28
|
12KB
|
469 lines
** Example for a very simple Object-Class.
** It shows a sizeable picture
**
** (c) 1994 by Michael Friedrich
** All Rights Reserved.
**
** You may use parts of this code to create your own private TCLibs.
** You are also allowed to publish these TCLibs as long as I will get
** a copy them.
**
include 'lvos.i'
include 'tclib.i'
startall:
moveq #-13,d0 ; if user tries to start this lib!
rts ; (need -13 to identify TClibs!)
dc.l 'TCLB' ; TurboCalc-Lib - this field is used to identify
; TClibs and to link them in memory (i.e. that
; this entry is used and thus changed by TC
; to keep a list of all already loaded libs!)
dc.l 'OBJT'
dc.w 1,0 ; Version, Revision
dc.l txt_name
dc.l txt_ver
dc.l txt_author
dc.l 0 ; flags - reserved
dc.l 0 ; reserved
dc.l 0 ; reserved
* default-routines
dc.l objclass_init ; init
dc.l 0 ; exit
dc.l 0 ; flush
dc.l 0
*
objclass_pic:
dc.l 0
dc.l objclass_picname
dc.l 'LOGO'
dc.b 0
dc.b 1<<OBJCLASSFLAGS1_ACTIONTASK
dc.b 0,0
dc.l objpic_new
dc.l objpic_duplicate
dc.l objpic_free
dc.l 0 ; for this example no edit-routine!
dc.l objpic_draw
dc.l objpic_load
dc.l objpic_save
dc.l objpic_action
objclass_picname: dc.b 'Iff-Logo (Example)',0
txt_name: dc.b '(Example) Logo-Objectclass',0
txt_ver: dc.b '$VER: Logo-Objectclass V1.0 (20.10.94)',0
txt_author: dc.b '© 1994 Michael Friedrich',0
cnop 0,2
STRUCTURE ObjPic,0
WORD objpic_depth
WORD objpic_width
WORD objpic_height
LABEL objpic_bitmap
* complete bitmap-structure
WORD objpicbm_BytesPerRow
WORD objpicbm_Rows
BYTE objpicbm_Flags
BYTE objpicbm_Depth
WORD objpicbm_Pad
STRUCT objpicbm_Planes,8*4
*
LABEL ObjPic_SIZE
STRUCTURE ObjPic_drawmem,0
LABEL objpicdm_scalearg
WORD bsa_SrcX ; source origin
WORD bsa_SrcY
WORD bsa_SrcWidth ; source size
WORD bsa_SrcHeight
WORD bsa_XSrcFactor ; scale factor denominators
WORD bsa_YSrcFactor
WORD bsa_DestX ; destination origin
WORD bsa_DestY
WORD bsa_DestWidth ; destination size result
WORD bsa_DestHeight
WORD bsa_XDestFactor ; scale factor numerators
WORD bsa_YDestFactor
LONG bsa_SrcBitMap ; source BitMap
LONG bsa_DestBitMap ; destination BitMap
LONG bsa_Flags ; reserved. Must be zero!
WORD bsa_XDDA ; reserved
WORD bsa_YDDA
LONG bsa_Reserved1
LONG bsa_Reserved2
WORD objpicdm_tempwidth
WORD objpicdm_tempheight
LABEL objpicdm_bitmap2
WORD objpicbm2_BytesPerRow
WORD objpicbm2_Rows
BYTE objpicbm2_Flags
BYTE objpicbm2_Depth
WORD objpicbm2_Pad
STRUCT objpicbm2_Planes,8*4
LABEL ObjPic_drawmem_SIZE
objclass_init:
* nothing to init, simply check if we are running with V36+
GETGFX
cmp.w #36,$14(a6)
bhs.s 10$
moveq #-1,d0
rts
10$ moveq #0,d0
rts
**********************************
objpic_new:
movem.l d2-d7/a2-a3,-(sp)
moveq #ObjPic_SIZE,d0
XSR AllocMemClear
beq.s 90$
move.l a0,a3
*
moveq #2,d0 ; depth
moveq #$4b,d1 ; width
moveq #$20,d2 ; height
movem.w d0-d2,objpic_depth(a3)
*
lea objpic_bitmap(a3),a0
GETGFX
CALL _LVOInitBitMap
*
lea objpicbm_Planes(a3),a2
move.l #AppIcon_p,(a2)+
move.l #AppIcon_p+($50/8)*$20,(a2)
*
move.l a3,d0
moveq #0,d1 ; no _EDIT needed!
90$ movem.l (sp)+,d2-d7/a2-a3
rts
objpic_duplicate
move.l a0,-(sp)
moveq #ObjPic_SIZE,d0
XSR AllocMemClear
beq.s 90$
move.l (sp),a1
move.l a0,(sp)
moveq #ObjPic_SIZE/2-1,d0
21$ move.w (a1)+,(a0)+
dbra d0,21$
move.l (sp),a0
move.l a0,d0
90$ addq.w #4,sp
rts
objpic_free
XMP FreeMem
objpic_draw
movem.l d0-d7,-(sp)
sub.l d0,d2
sub.l d1,d3
addq.l #1,d2
addq.l #1,d3
moveq #0,d6
cmp.w #1000,d2 ; BlitScale fails, if with >1008
blo.s 40$ ; so divide if it should be bigger
move.l d2,-(sp)
divu #1000,d2
addq.w #1,d2 ; divide in d2 pieces!!!
move.w d2,d6
swap d6
move.l (sp)+,d2
40$ moveq #0,d7
cmp.w #1000,d3 ; for height this seems to work, but
blo.s 50$ ; do it never the less for height, too.
move.l d3,-(sp) ; first to be sure and second
divu #1000,d3 ; and second to limit temp-bitmap!!!)
addq.w #1,d3 ; divide in d3 pieces!!!
move.w d3,d7
swap d7
move.l (sp)+,d3
*** loop for all parts
50$ movem.l d0-d5/a0-a1,-(sp)
* d6/d7-1):
move.l d6,d4
swap d4
tst.w d4
beq.s 51$
divu d4,d2
move.l d2,d5
mulu d6,d2
add.l d2,d0 ; add width/n * k
moveq #0,d2
move.w d5,d2
subq.w #1,d4
cmp.w d4,d6
bne.s 51$
swap d5
add.w d5,d2 ; is last part, so add modula
51$ move.l d7,d4
swap d4
tst.w d4
beq.s 52$
divu d4,d3
move.l d3,d5
mulu d7,d3
add.l d3,d1 ; add height/n * k
moveq #0,d3
move.w d5,d3
subq.w #1,d4
cmp.w d4,d7
bne.s 52$
swap d5
add.w d5,d3 ; is last part, so add modula
52$ movem.l 4*4(sp),d4/d5
*
bsr.s objpic_draw2
movem.l (sp)+,d0-d5/a0-a1
addq.w #1,d6
move.l d6,d5
swap d5
cmp.w d5,d6
blo.s 50$
*
clr.w d6
addq.w #1,d7
move.l d7,d5
swap d5
cmp.w d5,d7
blo.s 50$
movem.l (sp)+,d0-d7
rts
* d0-d3: x/y/w/h, d6/d7: upper-word: #pieces, lower-word: piece-number (w/h)
objpic_draw2:
movem.l d0-d7/a2-a4,-(sp)
move.l a0,a3
*** alloc second bitmap and blitscale-structure
moveq #ObjPic_drawmem_SIZE,d0
XSR AllocMemClear
beq 90$
move.l a0,a4
*** fill blitscale-structure!
lea objpicdm_scalearg(a4),a1
clr.l (a1)+ ; source_x/y
movem.w objpic_width(a3),d0-d1
* d6/d7-2):
movem.l d4/d5,-(sp)
move.l d6,d4
swap d4
tst.w d4
beq.s 21$
divu d4,d0
move.l d0,d5
mulu d6,d0
move.w d0,-4(a1) ; new x-pos: width/n * k
move.w d5,d0
subq.w #1,d4
cmp.w d4,d6
bne.s 21$
swap d5
add.w d5,d0 ; is last part, so add modula
21$ move.l d7,d4
swap d4
tst.w d4
beq.s 22$
divu d4,d1
move.l d1,d5
mulu d7,d1
move.w d1,-2(a1) ; new y-pos: height/n * k
move.w d5,d1
subq.w #1,d4
cmp.w d4,d6
bne.s 22$
swap d5
add.w d5,d1 ; is last part, so add modula
22$ movem.l (sp)+,d4/d5
*
move.w d0,(a1)+ ; source_width/height
move.w d1,(a1)+
move.w d0,(a1)+ ; source_factor
move.w d1,(a1)+
clr.l (a1)+ ; dest_x/y (are 0 for temp-bitmap!!!)
clr.l (a1)+ ; dest_w/h, is calculated by routine!
move.w d2,(a1)+ ; dest_factor
move.w d3,(a1)+ ; "
*
lea objpic_bitmap(a3),a0
move.l a0,(a1)+ ; source-bitmap
lea objpicdm_bitmap2(a4),a0
move.l a0,(a1)+ ; mid-bitmap
clr.l (a1)+ ; flags
*** init temp-bitmap!!!
* calc width
lea objpicdm_scalearg(a4),a0
move.w bsa_SrcWidth(a0),d0
move.w bsa_XDestFactor(a0),d1
move.w bsa_XSrcFactor(a0),d2
CALL -684 ; LVOScalerDiv
*
move.l d0,-(sp)
lea objpicdm_scalearg(a4),a0
move.w bsa_SrcHeight(a0),d0
move.w bsa_YDestFactor(a0),d1
move.w bsa_YSrcFactor(a0),d2
CALL -684 ; LVOScalerDiv
move.l d0,d2
move.l (sp)+,d1
move.w objpic_depth(a3),d0
* compare to dest-values and use higher ones!
cmp.w 2+2*4(sp),d1
bls.s 31$
move.w 2+2*4(sp),d1
31$ cmp.w 2+3*4(sp),d2
bls.s 32$
move.w 2+3*4(sp),d2
32$ movem.w d1/d2,objpicdm_tempwidth(a4)
lea objpicdm_bitmap2(a4),a0
movem.l d0-d2/a0,-(sp)
CALL _LVOInitBitMap
* alloc mem for temp-bitmap
movem.l (sp)+,d0-d2/a0
exg.l d0,d1
exg.l d1,d2
lea 8(a0),a0
35$ movem.l d0-d2/a0,-(sp) ; x/y/w
CALL _LVOAllocRaster
move.l d0,d3
movem.l (sp)+,d0-d2/a0
move.l d3,(a0)+
* well, no error checking here (but as this is only a test-objectclass
* i was too lazy :)
subq.w #1,d2
bne.s 35$
*** blit & scale from first bitmap to temp-bitmap
lea objpicdm_scalearg(a4),a0
CALL -678 ; _LVOBitMapScale
*** blit temp to rastport
lea objpicdm_bitmap2(a4),a0
move.l a2,a1
moveq #0,d0 ; temp-x/y
moveq #0,d1
movem.l (sp),d2-d5 ; dest-x/y/w/h
move.w #$c0,d6 ; copy!
CALL _LVOBltBitMapRastPort
*** free allocated structure(s) and end
* free raster
50$ moveq #0,d2
move.b objpicbm2_Depth(a4),d2
lea objpicbm2_Planes(a4),a3
51$ move.l (a3)+,a0
movem.w objpicdm_tempwidth(a4),d0-d1
CALL _LVOFreeRaster
subq.w #1,d2
bne.s 51$
** free temp-structure
move.l a4,a0
XSR FreeMem
90$ movem.l (sp)+,d0-d7/a2-a4
rts
objpic_load
tst.l d0
bne.s 10$
* d0=0: ask for 6 bytes to load!
moveq #6,d0
suba.l a0,a0
rts
* d0=1, a0=*mem for the requested 6 bytes - there aren't used here!
10$ bsr objpic_new
move.l d0,a0
moveq #0,d0 ; free the allocated mem!
rts
objpic_save:
* normally you needn't save any data for this test-objectclass
* to show saving, depth, width and height of the picture are written
* a0 is set, needn't change
moveq #6,d0 , write first 6 bytes of a0
moveq #0,d1 ; do not free this mem
rts
objpic_action:
* no action, simply return...
moveq #0,d0
rts
SECTION Graphic,DATA_C
AppIcon_p:
dc.w $7fff,$ffff,$ffff,$ffff,$ffc0
dc.w $4040,$1002,$0040,$0801,$0040
dc.w $7fff,$ffff,$ffff,$ffff,$ffc0
dc.w $4040,$0000,$0000,$0000,$0040
dc.w $404b,$81c0,$36b5,$c000,$0040
dc.w $404a,$01c0,$3e80,$0000,$0040
dc.w $6a80,$0000,$0000,$0000,$0040
dc.w $4040,$0000,$0000,$0000,$0040
dc.w $4042,$8000,$7e00,$001c,$0040
dc.w $4042,$8000,$7e00,$0014,$0040
dc.w $5540,$0000,$0000,$0000,$0040
dc.w $4040,$0000,$0000,$0000,$0040
dc.w $4049,$0180,$3808,$8000,$0040
dc.w $4049,$0180,$3808,$0000,$0040
dc.w $6ac0,$0000,$0000,$0000,$0040
dc.w $4046,$0000,$0000,$0000,$0040
dc.w $4046,$0700,$001f,$ffff,$ffc0
dc.w $4040,$0000,$001f,$ffff,$ffc0
dc.w $5540,$0000,$0010,$0000,$0040
dc.w $4040,$0000,$0011,$3800,$1c40
dc.w $4040,$07a0,$1e11,$3800,$1c40
dc.w $4040,$05e0,$0f11,$381c,$1c40
dc.w $6ac0,$0000,$0011,$3f1c,$1c40
dc.w $4040,$0000,$0011,$3f1c,$1c40
dc.w $4042,$8000,$0013,$ffff,$ff40
dc.w $4042,$8000,$0011,$0003,$8040
dc.w $6ae0,$0000,$0011,$0003,$8040
dc.w $4040,$0000,$0011,$0003,$8040
dc.w $4040,$0000,$0010,$0000,$0040
dc.w $7fff,$ffff,$ffff,$ffff,$ffc0
dc.w $0000,$0000,$0000,$0000,$0000
dc.w $0000,$0000,$0000,$0000,$0000
dc.w $0000,$0000,$0000,$0000,$0000
dc.w $0007,$00e0,$1c03,$8070,$1c00
dc.w $0000,$0000,$0000,$0000,$0000
dc.w $003f,$effd,$ffbf,$f7fe,$ff80
dc.w $0e34,$7fff,$c94a,$3fff,$ff80
dc.w $0031,$effd,$c13f,$f7fe,$ff80
dc.w $0015,$5555,$5555,$5555,$5500
dc.w $003f,$effd,$ffbf,$f7fe,$ff80
dc.w $0e3d,$7fff,$ffff,$ffe3,$ff80
dc.w $003d,$6ffd,$ffbf,$f7ea,$ff80
dc.w $0015,$5555,$5555,$5555,$5500
dc.w $003f,$effd,$ffbf,$f7fe,$ff80
dc.w $0e36,$fe7f,$c7f7,$7fff,$ff80
dc.w $0036,$ee7d,$c7b7,$f7fe,$ff80
dc.w $0015,$5555,$5555,$5555,$5500
dc.w $0039,$effd,$ffbf,$f7fe,$ff80
dc.w $0e39,$f8ff,$ffe0,$0000,$0000
dc.w $003f,$effd,$ffaf,$ffff,$ff80
dc.w $0005,$5555,$554f,$ffff,$ff80
dc.w $003f,$effd,$ffae,$ffff,$ff80
dc.w $0e3f,$f85f,$ffee,$ffff,$ff80
dc.w $003f,$ea1d,$f0ae,$ffff,$ff80
dc.w $0015,$5555,$554e,$f8ff,$ff80
dc.w $003f,$effd,$ffae,$f8ff,$ff80
dc.w $0e3d,$7fff,$ffec,$0000,$0080
dc.w $003d,$6ffd,$ffae,$fffc,$7f80
dc.w $0015,$5555,$554e,$fffc,$7f80
dc.w $003f,$effd,$ffae,$fffc,$7f80
dc.w $0e3f,$ffff,$ffef,$ffff,$ff80
dc.w $0000,$0000,$0000,$0000,$0000
dc.w $0000,$0000,$0000,$0000,$0000
dc.w $0000,$0000,$0000,$0000,$0000
END